﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.Windows.Data;

namespace Microsoft.Samples.Office.UnifiedCommunications.Gadget
{
    public enum ClickAction
    {
        None,
        InstantMessage,
        CommunicatorCall,
        PhoneCall,
        VideoCall
    };

    public class DefaultClickAction
    {
        public ClickAction ClickActionValue { get; set; }
        public string ClickActionFriendlyName { get; set; }

        public static string EnumToFriendlyName(ClickAction clickAction)
        {
            string friendlyName = default(string);

            switch (clickAction)
            {
                case ClickAction.None:
                    friendlyName = default(string);
                    break;
                case ClickAction.InstantMessage:
                    friendlyName = "Instant Message";
                    break;
                case ClickAction.CommunicatorCall:
                    friendlyName = "Communicator Call";
                    break;
                case ClickAction.PhoneCall:
                    friendlyName = "Phone Call";
                    break;
                case ClickAction.VideoCall:
                    friendlyName = "Video Call";
                    break;
            };

            return friendlyName;
        }

        public static ClickAction FriendlyNameToEnum(string clickActionFriendlyName)
        {
            switch (clickActionFriendlyName)
            {
                case "Instant Message":
                    return ClickAction.InstantMessage;
                case "Communicator Call":
                    return ClickAction.CommunicatorCall;
                case "Phone Call":
                    return ClickAction.PhoneCall;
                case "Video Call":
                    return ClickAction.VideoCall;
                default:
                    return ClickAction.None;
            };
        }
    }
        
    public class DefaultClickActions : ObservableCollection<DefaultClickAction>
    {
        public DefaultClickActions()
        {
            base.Add(
                new DefaultClickAction
                {
                    ClickActionValue = ClickAction.None,
                    ClickActionFriendlyName = DefaultClickAction.EnumToFriendlyName(ClickAction.None)
                });

            base.Add(
                new DefaultClickAction 
                {
                    ClickActionValue = ClickAction.CommunicatorCall,
                    ClickActionFriendlyName = DefaultClickAction.EnumToFriendlyName(ClickAction.CommunicatorCall) 
                });

            base.Add(
                new DefaultClickAction 
                {
                    ClickActionValue = ClickAction.InstantMessage,
                    ClickActionFriendlyName = DefaultClickAction.EnumToFriendlyName(ClickAction.InstantMessage)
                });

            base.Add(
                new DefaultClickAction 
                {
                    ClickActionValue = ClickAction.PhoneCall,
                    ClickActionFriendlyName = DefaultClickAction.EnumToFriendlyName(ClickAction.PhoneCall) 
                });
        }
    }

    public class ClickActionConverterIM : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return false;
            else
                return DefaultClickAction.FriendlyNameToEnum(value.ToString()) == ClickAction.InstantMessage;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }

    public class ClickActionConverterPhoneCall : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return false;
            else
                return DefaultClickAction.FriendlyNameToEnum(value.ToString()) == ClickAction.PhoneCall;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }

    public class ClickActionConverterCommunicatorCall : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return false;
            else
                return DefaultClickAction.FriendlyNameToEnum(value.ToString()) == ClickAction.CommunicatorCall;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }
}